<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/8
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>智能门禁安装点修改</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet"/>

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
			<style >
		.jqGrid_wrapper{*+margin-left:270px;}
	
		.lt{float:left}
		.form-group{*+overflow:hidden;}
		.form-group label{width:28%\9;*+width:20%;text-align:right\9;*+text-align:right;}
		.col-sm-8 .m-t2 {width:22%\9;}
		.form-group .col-sm-8{width:66%\9;*+width:66%;}
		.form-group .form-control{*+width:95%;}

	</style>
</head>
<body>
<div class="col-sm-12">
    <form class="form-horizontal m-t" id="form" method="post"
          action="${pageContext.request.contextPath}/admin/tlocks_update.action">
        <input type="hidden" name="sid" value="${map.sid}">
        <input type="hidden" name="beforeunit" id="beforeunit" value="${map.unit}">
         <div class="form-group">
            <label class="col-sm-3  control-label lt"><i class="require">*</i>PID编号:</label>
            <div class="col-sm-8 lt">
                <input class="form-control" name="pid" size="30" value="${map.pid}" disabled="disabled"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label lt"><i class="require">*</i>类型:</label>
            <div class="col-sm-8 lt">
                <select name="type" id="type"  class="form-control">
                    <option value="1">公共门禁</option>
                    <option value="0">单元门禁</option>
                </select>
            </div>
        </div>
	    <div class="form-group">
	        <label class="col-sm-3 control-label lt"><i class="require">*</i>楼栋:</label>
	        <div class="col-sm-8 lt">
                  <select name="building" id="building" class="form-control"></select>
             </div>
	
	    </div>
       <div class="form-group">
            <label class="col-sm-3  control-label lt"><i class="require">*</i>单元:</label>
            <div class="col-sm-8 lt">
                  <select name="unit" id="unit" class="form-control"></select>
             </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3  control-label lt"><i class="require">*</i>门禁名称:</label>
            <div class="col-sm-8 lt">
                <input class="form-control" name="installLockName" id="installLockName" size="30" value="${map.install_lock_name}"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
$(function () {
	
    $("#type").val('${map.type}');
    if ('${map.type}' == 0) {
    	getBudiling();
    	getUnit();
    	 $("#building").append("<option>-</option>");  
   	     $("#unit").append("<option>-</option>");
	}else{
		$("#building").attr("disabled", "true");
		$("#unit").attr("disabled", "true");
	}
	
    $("#type").change(function() {  
   	 var selectType = $("#type").val();
  		 $("#building").empty();  
  	     $("#unit").empty(); 
   	 //公共门禁
  	     if(selectType == 1){
   		 $("#building").append("<option value='-1'>-</option>"); 
   		$("#building  option[value='-1'] ").attr("selected", true);  
   		$("#select2-building-container").html('-');  
   	     $("#unit").append("<option>-</option>");
   	  	$("#unit  option[value='-1'] ").attr("selected", true);  
 		$("#select2-unit-container").html('-'); 
   	     $("#building").attr("disabled", "true");
   	     $("#unit").attr("disabled", "true");
   	     $("#installLockName").val('');
   	     return;
   	 }
   	 //单元门禁
   	 $("#building").removeAttr("disabled");
	 getBudiling();
	 if('${map.type}' ==1){
		 $("#unit").attr("disabled", "true");
	 } else{
	 	$("#unit").removeAttr("disabled");
	 	getUnit();
	 }
	 $("#installLockName").val('${map.install_lock_name}');
   });

    $("#building").change(function() {  
      	 var selectBuilding = $("#building").val();
      	 $("#unit").empty(); 
      	 $("#unit").removeAttr("disabled");
      	getUnit(selectBuilding);
  	  	setName();
  });
   
   $("#unit").change(function() {  
   	setName();
 });
   
})
 function getBudiling() {  
        $.post("${pageContext.request.contextPath}/admin/cbuilding_list.action",function (data) {
            $("#building").empty();
            $("#building").append("<option value=''>请选择楼栋</option>");
            for (var i = 0; i < data.length; i++) {
                $("#building").append("<option value='" + data[i].sid + "'>" + data[i].cbName + "</option>");
            }
            $("#building  option[value='${map.building}'] ").attr("selected", true); 
            $("#building").select2({
                "placeholder": "请选择楼栋",
                "width": "100%"
            })
        }, "json");
    }  
    
    function getUnit(selectBuilding) {  
		var bsid;
		var unionId;
        if(typeof(selectBuilding) != "undefined"){
        	bsid = selectBuilding;
            if(selectBuilding == '${map.building}'){
            	unionId = '${map.unit}';
           	}
        }else{
        	bsid = '${map.building}';
        	unionId = '${map.unit}';
        }
    	$.post("${pageContext.request.contextPath}/admin/cinstallunit_listUnit.action",{"bsid": bsid,"type":"edit","unionId":unionId},function (data) {
            $("#unit").empty();
            $("#unit").append("<option value=''>请选择单元</option>");
            for (var i = 0; i < data.length; i++) {
                $("#unit").append("<option value='" + data[i].SID + "'>" + data[i].CBNAME + "</option>");
            }
            if(typeof(selectBuilding) == "undefined"){
            	$("#unit  option[value='${map.unit}'] ").attr("selected", true);
            }
            $("#unit").select2({
                "placeholder": "请选择单元",
                "width": "100%"
            })
        }, "json");
    } 
    function setName(){
    	var buding = $("#building").find("option:selected").text();
        var unit = $("#unit").find("option:selected").text();
        if(unit=='请选择'){
        	$("#installLockName").val(buding);
        }else{
        	$("#installLockName").val(buding+unit);
        }
    }
</script>
</body>
</html>
